﻿using System;
using System.Collections.Generic;
using System.Linq;
using CodeStash.Common.DataAccess.EntityFramework;
using CodeStash.Common.DataAccess.AspMembership;

namespace CodeStash.Models.Snippet
{

    public class CodeSnippetWrapperViewModel
    {
        public bool IsSnippetEditable { get; private set; }
        public CodeSnippet CodeSnippet { get; private set; }
        public string UserName { get; private set; }
 
        public CodeSnippetWrapperViewModel(bool isSnippetEditable, CodeSnippet codeSnippet)
        {
            this.IsSnippetEditable = isSnippetEditable;
            this.CodeSnippet = codeSnippet;

            UserName = new GetUserForRestService().GetUserFromEmail(codeSnippet.AspNetMembershipUserId.ToString());
        }
    }



    public class DisplaySnippetsViewModel
    {
        public static int MAX_SNIPPETS_TO_DISPLAY = 100;

        public DisplaySnippetsViewModel(
            List<CodeSnippetWrapperViewModel> codeSnippets, 
            DisplayMode displayMode,
            bool isTruncated,
            String highlightingCSS)
        {
            this.CodeSnippets = codeSnippets;
            this.DisplayMode = displayMode;
            this.IsTruncated = isTruncated;
            this.HighlightingCSS = highlightingCSS;
            IsGrouped = this.CodeSnippets.Any(x => x.CodeSnippet.GroupId.HasValue);

        }


        public bool IsGrouped { get; private set; }
        public List<CodeSnippetWrapperViewModel> CodeSnippets { get; private set; }
        public DisplayMode DisplayMode { get; private set; }
        public bool IsTruncated { get; private set; }
        public string HighlightingCSS  { get; private set; }

    }
}